package com.manong.config.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Set;
import java.util.concurrent.TimeUnit;

@Component
public class RedisService {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    //存
    public void set(String key,Object value,Long outTime){
        redisTemplate.opsForValue().set(key, value, outTime, TimeUnit.SECONDS);
    }
    //取
    public String get(String key){
        return (String)redisTemplate.opsForValue().get(key);
    }
    //删
    public void del(String key){
        redisTemplate.delete(key);
    }

    //永久缓存
    public void set(String key, Object value) {
        redisTemplate.opsForValue().set(key, value);
    }
    public Object getOut(String key){
        return redisTemplate.opsForValue().get(key);
    }
    public Set<String> getAllKeys() {
        return redisTemplate.keys("*"); // 获取所有 key
    }
}
